//
//  oldMessageView.m
//  laonianbang
//
//  Created by 勇拓 李 on 18/4/3.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldMessageView.h"
#import "oldMessageManager.h"
#import "AppDelegate.h"

@interface oldMessageView()<oldMessageDelegate>
@property (weak, nonatomic) IBOutlet UIView *red_point;
@property (nonatomic, strong)oldMessageManager *manager;
@end

@implementation oldMessageView


- (instancetype)init
{
    self = [[[NSBundle mainBundle] loadNibNamed:@"oldMessageView"
                                          owner:self
                                        options:nil] objectAtIndex:0];
    
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    _red_point.layer.cornerRadius = 11/2;
    _red_point.hidden = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMessageView:)];
    [self addGestureRecognizer:tap];
    
    _manager = [[oldMessageManager alloc] initWithType:newMessage];
    _manager.delegate = self;
    [_manager registerForNotifications];
}

- (void)addToView
{
    self.frame = CGRectMake(SCREEN_WIDTH - 55, 190, 55, 55);
    [[AppDelegate getMainWindow] addSubview:self];
}

- (void)removeView
{
    [self removeFromSuperview];
}

- (void)receiveMessage:(id)message type:(oldMessageType)type
{
    _red_point.hidden = NO;
}

- (void)tapMessageView:(id)sender
{
    _red_point.hidden = YES;
    [self.delegate messageViewTapped];
}

@end
